#include "common.h"
namespace common {
int minSubArrayLen(int target, std::vector<int> &nums) {
    if (nums.empty())
        return 0;
    int start = 0;
    int end = 0;
    const int N = nums.size();
    int min_length = std::numeric_limits<int>::max();
    int sum_value = 0;
    while (end < N) {
        sum_value += nums[end];
        while (sum_value >= target && start < N) {
            min_length = std::min(end - start + 1, min_length);
            sum_value -= nums[start];
            start++;
        }
        end++;
    }
    return min_length == std::numeric_limits<int>::max() ? 0 : min_length;
}
} // namespace common
